docs
Start
1
| from omegaconf import OmegaConf
|
Create
You can create OmegaConf objects from multiple sources.
From dict
1 2 3 4 5 6 7 8 9
| conf = OmegaConf.create({"k" : "v", "list" : [1, {"a": "1", "b": "2", 3: "c"}]}) print(OmegaConf.to_yaml(conf))
k: v list: - 1 - a: '1' b: '2' 3: c
|
From list
1 2 3 4 5 6 7 8
| conf = OmegaConf.create([1, {"a":10, "b": {"a":10, 123: "int_key"}}]) print(OmegaConf.to_yaml(conf))
- 1 - a: 10 b: a: 10 123: int_key
|
From yaml
1 2 3 4 5 6 7 8 9 10 11 12
| conf = OmegaConf.load('source/example.yaml')
print(OmegaConf.to_yaml(conf))
server: port: 80 log: file: ??? rotation: 3600 users: - user1 - user2
|
From dot-list
1 2 3 4 5 6 7 8 9 10 11
| dot_list = ["a.aa.aaa=1", "a.aa.bbb=2", "a.bb.aaa=3", "a.bb.bbb=4"] conf = OmegaConf.from_dotlist(dot_list) print(OmegaConf.to_yaml(conf))
a: aa: aaa: 1 bbb: 2 bb: aaa: 3 bbb: 4
|
From command line arguments
1 2 3 4 5 6 7 8
| sys.argv = ['your-program.py', 'server.port=82', 'log.file=log2.txt'] conf = OmegaConf.from_cli() print(OmegaConf.to_yaml(conf))
server: port: 82 log: file: log2.txt
|